<template>
    <div id="app">
        <!--页面导航栏-->
        <Header></Header>

        <!--页面主体部分-->
        <div class="all">
            <router-view/>
        </div>

    </div>
</template>

<script>
    import Header from "@/components/header/Header"
    import {getCookie} from "@/tools/cookie";

    export default {
        name: "",
        components: {
            Header
        },
        data() {
            return {}
        },
        methods: {
            init:function () {
                let cookieToken = getCookie("token");
                let cookieUserInfo = getCookie("userInfo");
                let cookieIsLogin = getCookie("isLogin");
                if (cookieToken != null) {
                    window.sessionStorage.setItem("token", cookieToken);
                }
                if (cookieUserInfo != null) {
                    window.sessionStorage.setItem("userInfo", cookieUserInfo);
                }
                if (cookieIsLogin != null) {
                    window.sessionStorage.setItem("isLogin", cookieIsLogin);
                }

                let token = window.sessionStorage.getItem("token");
                let userInfo = window.sessionStorage.getItem("userInfo");
                let isLogin = window.sessionStorage.getItem("isLogin");
                let user = JSON.parse(userInfo);
                this.isLogin = isLogin

                this.$store.dispatch("updateId", user == null ? "" : user.userId);
                this.$store.dispatch("updateIsLogin", isLogin);
                this.$store.dispatch("updateToken", token);
                this.$store.dispatch("updateUserInfo", user);
            }
        },
        mounted() {
            window.addEventListener("unload", this.init())
        }
    }
</script>

<style>
    * {
        margin: 0px;
        padding: 0px;
        text-decoration: none; /*下划线*/
        list-style: none; /* ul li 的小圆点*/
        font-family: Arial; /*字体*/
        font-size: 16px; /*文字大小*/
    }


    #app .all {
        min-height: calc(100vh - 70px);
        margin: 0 auto;
    }
</style>
